package com.wanpinghui.wphlibrary.photovideo.bean;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Parcel;
import android.os.Parcelable;


import java.util.ArrayList;
import java.util.List;

/***
 * 功能描述:(图片上传Recycler的实体类)
 * 作者:qiujialiu
 * 时间:2016/12/21
 * 版本:1.0
 ***/

public class UploadFileBean extends BaseUrlBean implements Parcelable {
    public static final int STATUS_COMMON = 0;
    public static final int STATUS_WAIT_UPLOAD = 1;
    public static final int STATUS_BEGIN_UPLOAD = 2;
    public static final int STATUS_UPLOADING = 3;

    // private String type;//类型 视频:video  图片:image 添加更多:other
    //private String path;//地址
    private int status;//状态 0:默认 1:待上传 2:开始上传  3:上传中 4:上传失败
    private boolean finishDelete;//上传完成是否删除
    private double process;
    private int sort;
    private String forderPath;

    public UploadFileBean(int type) {
        this.type = type;
    }

    public UploadFileBean(int type, String path) {
        this.type = type;
        this.url = path;
    }

    public UploadFileBean(int type, String path,Integer height,Integer width ) {
        this.type = type;
        this.url = path;
        this.height = height;
        this.width = width;
    }

    public UploadFileBean(int type, String path, boolean finishDelete) {
        this.type = type;
        this.url = path;
        this.finishDelete = finishDelete;
    }

    public UploadFileBean() {
    }




    public static ArrayList<UploadFileBean> create(List<String> paths) {
        ArrayList<UploadFileBean> beans = new ArrayList<>();
        if (paths != null && paths.size() > 0) {
            for (String path : paths) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                 BitmapFactory.decodeFile(path, options);
                int w = options.outWidth;
                int h = options.outHeight;
                beans.add(new UploadFileBean(1, path,h,w));
            }
        }
        return beans;
    }

    public static ArrayList<String> from(List<UploadFileBean> paths) {
        ArrayList<String> beans = new ArrayList<>();
        if (paths != null && paths.size() > 0) {
            for (UploadFileBean path : paths) {
                beans.add(path.getPath());
            }
        }
        return beans;
    }

    public static boolean haveVideo(List<UploadFileBean> paths) {
        if (paths != null && paths.size() > 0) {
            for (UploadFileBean path : paths) {
                if (path.getType() == 2) {
                    return true;
                }
            }
        }
        return false;
    }

    public String getForderPath() {
        return forderPath;
    }

    public void setForderPath(String forderPath) {
        this.forderPath = forderPath;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getPath() {
        return url;
    }

    public void setPath(String path) {
        this.url = path;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isFinishDelete() {
        return finishDelete;
    }

    public void setFinishDelete(boolean finishDelete) {
        this.finishDelete = finishDelete;
    }

    public double getProcess() {
        return process;
    }

    public void setProcess(double process) {
        this.process = process;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.status);
        dest.writeByte(this.finishDelete ? (byte) 1 : (byte) 0);
        dest.writeDouble(this.process);
        dest.writeInt(this.sort);
        dest.writeString(this.forderPath);
        dest.writeString(this.url);
        dest.writeInt(this.type);
        dest.writeInt(this.seq_);
        dest.writeInt(this.width);
        dest.writeInt(this.height);
        dest.writeString(this.thumb_url);
    }

    protected UploadFileBean(Parcel in) {
        this.status = in.readInt();
        this.finishDelete = in.readByte() != 0;
        this.process = in.readDouble();
        this.sort = in.readInt();
        this.forderPath = in.readString();
        this.url = in.readString();
        this.type = in.readInt();
        this.seq_ = in.readInt();
        this.width = in.readInt();
        this.height = in.readInt();
        this.thumb_url = in.readString();
    }

    public static final Creator<UploadFileBean> CREATOR = new Creator<UploadFileBean>() {
        @Override
        public UploadFileBean createFromParcel(Parcel source) {
            return new UploadFileBean(source);
        }

        @Override
        public UploadFileBean[] newArray(int size) {
            return new UploadFileBean[size];
        }
    };
}
